package edu.zjucst.spb.controller.stage;

import edu.zjucst.spb.domain.ResponseResult;
import edu.zjucst.spb.domain.param.stage.joinParty.TODOTaskQueryParam;
import edu.zjucst.spb.domain.vo.flow.joinParty.MyProcessTaskVO;
import edu.zjucst.spb.domain.param.stage.joinParty.MyProcessQueryParam;
import edu.zjucst.spb.service.JoinPartyFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZlunYan
 * @description
 * @create 2023-11-30
 */

@RestController
@Slf4j
@Api(value = "入党流程相关接口", tags = {"入党流程相关接口"})
@RequestMapping("/joinParty")
public class JoinPartyController {

    @Autowired
    private JoinPartyFlowService joinPartyFlowService;

    @ApiOperation("申请入党")
    @PostMapping("/process")
    public ResponseResult<Object> startProcess(@ApiParam("学工号[测试用]") @Validated String userId, @ApiParam("支部名称[测试用]") @Validated String branchName) {
        joinPartyFlowService.startProcess(userId, branchName);
        return ResponseResult.success();
    }

    @ApiOperation("查询申请入党流程状态")
    @GetMapping("/process")
    public ResponseResult<MyProcessTaskVO> queryMyProcess(MyProcessQueryParam param) {
//        joinPartyFlowService.queryMyCreateProcess(userId);
        return ResponseResult.success(joinPartyFlowService.queryMyCreateProcess(param.getPageNumber(), param.getPageSize(), param.getUserNumber()));
    }

    @ApiOperation("查询当前需要处理的申请入党流程任务")
    @GetMapping("/process/todo")
    public ResponseResult<MyProcessTaskVO> queryTODOProcessTask(TODOTaskQueryParam param) {
//        joinPartyFlowService.queryMyTODOProcess(branchId);
        return ResponseResult.success(joinPartyFlowService.queryMyTODOProcess(param.getPageNumber(), param.getPageSize(), param.getBranchName()));
    }

    @ApiOperation("根据任务id审批任务节点(后续更新)")
    @PostMapping("/process/audit")
    public ResponseResult<Object> completeTask(@Validated String taskId, @Validated boolean accept) {
        // TODO 如果在入党申请书阶段被拒接的话 需要将process_id 置为 null 销毁
        joinPartyFlowService.simpleCompleteTaskByTaskId(taskId, accept);
        return ResponseResult.success();
    }

}
